import {ADD_NUM,ADD_TO_CAR} from "./mutations-types"
export default {
  addCart(context, payload) {
    return new Promise((resolve, reject) => {
      let oldCartList = context.state.cartList.find(item => item.id == payload.id)
      if (oldCartList) {
        context.commit(ADD_NUM,oldCartList)
        resolve('当前的商品数量+'+oldCartList.num)
      }else {
        context.commit(ADD_TO_CAR,payload)
        resolve('添加了新的商品')
      }
    })
  }
}
